#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    resize(800,600);
    QPushButton* Btn1 = new QPushButton("btn1", this);
    QPushButton* Btn2 = new QPushButton("btn2", this);

    int m = 10; //定义局部变量

    Btn1->move(300, 100);
    Btn2->move(500, 100);

    //添加mutable声明后，可以修改局部变量m的拷贝
    connect(Btn1, &QPushButton::clicked,this,[m]()mutable{m=20; qDebug()<<m;});

    //没有添加mutable声明，局部变量m的拷贝不可修改
    connect(Btn2, &QPushButton::clicked,this,[m](){qDebug() << m;});

    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}
